﻿<cfsilent>

	<cfset jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice") />

	<cfset teacherArray = arrayNew(1) />
	<cfif event.isArgDefined('Keywords') AND len(event.getArg('Keywords'))>
		<cfscript>
			
			sql = "	SELECT
						t.tch_id,t.tch_name,t.tch_sex,i.institute_short
					FROM
						t_teacher t
						INNER JOIN t_institute i ON i.institute_id = t.institute_id
					WHERE
						t.tch_id LIKE :keyword 
						OR 
						t.tch_name LIKE :keyword 
					ORDER BY
						t.tch_name ASC";
			
        	queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "keyword", value = event.getArg('Keywords') & '%', cfsqltype = "cf_sql_varchar");
			rs_teacher = queryObj.execute(sql = sql).getResult();

			teacherArray = [];

			for(a = 1; a lte rs_teacher.recordCount; a++){
				arrayAppend(teacherArray,[rs_teacher['tch_id'][a],rs_teacher['tch_name'][a],rs_teacher['tch_sex'][a],rs_teacher['institute_short'][a]]);
			}
			
        </cfscript>
	</cfif>
</cfsilent><cfoutput>#jsonAdvice.encode(data:teacherArray, stringNumbers:true)#</cfoutput>